<?php
namespace Home\Controller;
use Think\Controller;
class UController extends CommonController {
    public function index(){

    // 
    // // D 是实例化模型的方法
    // $this->assign('question',$question);
    //接受return回来的答案后分配到模板
    //
    if (isset($_GET['id'])) {
    	$id = $_GET['id'];
    }else{
    	$id = $_SESSION['id'];   //把$_SESSION里面的id存到id里
    }
    
    $sql = "select * from user where id = {$id}";
 
    $user = M('user')->query($sql);		//M  取数据库里的某一项
 	
 	$user = current($user);   //取当前

    $this->assign('user',$user);
    //接受return回来的答案后分配到模板
    //

   	$sql = "select t1.* from question t1 where t1.uid={$id} order by create_time desc";   //左边的


        //关联表查询数据，问题表中t1所有数据，用户表中t2中只要昵称，需要什么取什么
    $question = M()->query($sql);  
        //实例化
    $this->assign('question',$question);


 	$sql = "select t1.*,t2.* from question t1 inner join answer t2 on t1.id=t2.qid and t2.uid={$id} order by t2.create_time desc ";
    	$answer=M()->query($sql);
    	// var_dump($answer);
    	$this->assign('answer',$answer);
    $this->display();
    }


    public function mycenter()
    {
        //我发的帖子
        $sql = "select t1.* from question t1 where t1.uid={$_GET['id']} order by create_time desc";
        $question = M()->query($sql);  //实例化
        $this->assign('question',$question);   //分配到模板
    

        //我收藏的帖子
        $sql="select t1.*, t2.id,t2.title from store t1 inner join question t2 where t1.uid={$_GET['id']} and t1.qid=t2.id order by t1.create_time desc";

        $store = M()->query($sql);  //实例化
        $this->assign('store',$store);   //分配到模板
        $this->display();
    }
}